********************************************************************************
*                                                                              *
*    FIRM-LEVEL ANALYSES OF THE IMPACT OF ROBOT ADOPTION (LONG DIFFERENCES)    *
*                                                                              *
********************************************************************************

cd "H:\"

// Variable list for long-differences regressions
global fdweightvar hoursworked09
global fdcvar logworkers09 logvalueaddedpworker09
global fdfe sbi4 mun year

// What do we do below:
*1) Long differences
		
////////////////////////////////////////////////////////////////////////////////
///////////////////////1) LONG-DIFFERENCES REGRESSIONS//////////////////////////
////////////////////////////////////////////////////////////////////////////////

* Create Table B1, Panel A

use "Data\BEID_PS.dta", clear
keep if manufacturing==1

// Descriptives
keep if year == 2009 | year == 2020

foreach var in robots logvalueadded logvalueaddedphour laborshare loghwage loghoursworked logsalesphour capitalratio compete {
	g Δ`var' = `var'[_n+1]-`var' if beid == beid[_n+1]

}
label variable Δrobots "Robot adopter"
label variable Δcompete "Share of sales in robot adopting firms"
label variable logworkers "Number of workers in t-6 \textit{(log)}"
label variable logvalueaddedpworker "Value added per worker in t-6 \textit{(log)}"


sort beid year

reghdfe Δlogvalueadded Δrobots $fdcvar [weight=$fdweightvar], absorb($fdfe) vce(robust)
estimates store weighted1
reghdfe Δlaborshare Δrobots $fdcvar [weight=$fdweightvar], absorb($fdfe) vce(robust) 
estimates store weighted3
reghdfe Δloghwage Δrobots $fdcvar [weight=$fdweightvar], absorb($fdfe) vce(robust)
estimates store weighted4
reghdfe Δloghoursworked Δrobots $fdcvar [weight=$fdweightvar], absorb($fdfe) vce(robust)
estimates store weighted5

qui estimates restore weighted1
qui outreg2 using "Results\Longdifferences_weighted", label aster replace word tex ctitle(GVA \textit{(log)}) nocon addnote(Notes: we weight the number of observations by the hours worked in 2009. We include 4-digit industry code and municipality fixed effects and in all specifications.)
qui estimates restore weighted3
qui outreg2 using "Results\Longdifferences_weighted", label aster append word tex ctitle(Labor share) nocon
qui estimates restore weighted4
qui outreg2 using "Results\Longdifferences_weighted", label aster append word tex ctitle(Hourly wage \textit{(log)}) nocon
qui estimates restore weighted5
    outreg2 using "Results\Longdifferences_weighted", label aster append word tex ctitle(Capital/value added) nocon
	